package com.softeem.utils;

import com.alibaba.druid.filter.Filter;
import com.alibaba.druid.filter.logging.Log4jFilter;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;



public class BaseDao {

    private static DataSource ds;

    static {
        try {
            InputStream in = BaseDao.class.getClassLoader().getResourceAsStream("druid.properties");

            Properties properties = new Properties();

            properties.load(in);

            ds = DruidDataSourceFactory.createDataSource(properties);

            DruidDataSource dataSource = (DruidDataSource) ds;

            Log4jFilter log4jFilter = new Log4jFilter();
            log4jFilter.setStatementExecutableSqlLogEnable(true);

            List<Filter> list = new ArrayList<>();
            list.add(log4jFilter);

            dataSource.setProxyFilters(list);

        } catch(Exception e) {
            e.printStackTrace();
        }
    }


    public static DataSource getDs(){
        return ds;
    }

}
